<?php 
    //print_r($this->packagesItems);
    $shipCount = count($this->packages);    
    $url = HttpUtil::baseUrl();
?>  
<table class="order_table">
	<thead>
	    <tr  class="table_header">
            <td style="width: 10px;" >
            <?php 
                if($this->edit=='true'){
                    echo '<input type="button" id="add_package_btn" name="add_package_btn" value="'.$this->translate("addNewPackage").'" onclick="Order.openPackageDialog(\''.HttpUtil::baseUrl().'\','.$this->orderId.')" />';
                }
            ?>
            </td>
            <td><?php echo $this->translate("title"); ?></td>
            <td><?php echo $this->translate("upc"); ?></td>
            <td><?php echo $this->translate("qty"); ?></td>
            <td><?php echo $this->translate("salePrice"); ?></td>
            <td><?php echo $this->translate("attribute"); ?></td>
            <?php 
               
                for($i=0;$i<$shipCount;$i++){
                    $shippingMethod = OrderConstant::getShippingMethod($this->packages[$i]['shipping_method_id']);
                    echo "<td>{$shippingMethod}<br/>{$this->packages[$i]['tracking_num']}</td>";
                }
            ?>
   		</tr>
	</thead>
	
	<tbody>
        <?php foreach($this->items as $item){?>
        <tr>
            <td style="width: 10px;">
            <?php  
                if($this->edit=='true'){
                    
                    $itemCount = 0;
                    for($i=0;$i<$shipCount;$i++){
                        $packageId = $this->packages[$i]['id'];
                        $itemId = $item['oiid'];
                        if($this->packagesItems[$packageId][$itemId]['qty']>0){
                           $itemCount = $itemCount + $this->packagesItems[$packageId][$itemId]['qty'];
                        }
                    }
                    if($itemCount == $item['quantity']){
                        echo '<input type="checkbox" name="order_item_chk[]" value="'.$item["oiid"].'" disabled="disabled"/>';
                    }else{
                        echo '<input type="checkbox" name="order_item_chk[]" value="'.$item["oiid"].'"/>';
                    }
                }
            ?>
            </td>
            <td><a style="text-decoration:none;color:#0055ff;" href="<?php echo HttpUtil::baseUrl().'/inventory/product/edit/id/'.$item['product_id']; ?>"  target="_blank" ><?php echo $item["title"]; ?></a></td>
            <td><?php echo $item['upc'];?></td>
            <td><?php echo $item['quantity']; ?></td>
            <td><?php echo $item['sale_price']; ?></td>
            <td>
                <?php if (! empty($item['value_1'])) {?>
                <span><div align="center"><?php echo $item['attribute_1']; ?>:<label><?php echo $item['value_1']; ?></label></div></span>
                <?php } ?>
                <?php if (! empty($item['value_2'])) {?>
                <span><div align="center"><?php echo $item['attribute_2']; ?>:<label><?php echo $item['value_2']; ?></label></div></span>
                <?php } ?>
                <?php if (! empty($item['value_3'])) {?>
                <span><div align="center"><?php echo $item['attribute_3']; ?>:<label><?php echo $item['value_3']; ?></label></div></span>
                <?php } ?>
                <?php if (! empty($item['value_4'])) {?>
                <span><div align="center"><?php echo $item['attribute_4']; ?>:<label><?php echo $item['value_4']; ?></label></div></span>
                <?php } ?>
                <?php if (! empty($item['value_5'])) {?>
                <span><div align="center"><?php echo $item['attribute_5']; ?>:<label><?php echo $item['value_5']; ?></label></div></span>
                <?php } ?>
            </td>
            
            <?php 
                for($i=0;$i<$shipCount;$i++){
                    $packageId = $this->packages[$i]['id'];
                    $itemId = $item['oiid'];
                    if($this->packagesItems[$packageId][$itemId]['qty']>0){
                        echo "<td>{$this->packagesItems[$packageId][$itemId]['qty']}</td>";
                    }else{
                        echo "<td>0</td>";
                    }
                }
            ?>
        </tr>
        <?php }
            if($shipCount>0&&$this->edit=='true'){
        ?>
        <tr>
            <td colspan="6"></td>

            <?php 
                for($i=0;$i<$shipCount;$i++){
                    $packageId = $this->packages[$i]['id'];
                    $itemId = $item['order_item_id'];
                    echo '<td>
                    	  <input type="button" value="'.$this->translate("editBtn").'" id="edit_package_btn" name="edit_package_btn" onclick="javascript:Order.editPackageDialog(\''.$url.'\','.$packageId.');">
                    	  <input type="button" value="'.$this->translate("delBtn").'" id="del_package_btn" name="del_package_btn" onclick="javascript:Order.delPackage(\''.HttpUtil::baseUrl().'\','.$packageId.','.$this->orderId.')">
                    	  </td>';
                }
            ?>
        </tr>
        <?php }?>
    </tbody>
</table>            


